/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package z.h.w.jar.data.time;

import java.util.ArrayList;
import java.util.List;
import z.h.w.jar.kit.method.To;

/**
 *
 * @author EnzoZhong
 * @date 2011.10.30
 */
public class TimeUtil implements TimeUtilApi {

      private TimeUtil () {
      }

      public static TimeUtil born () {
            return new TimeUtil ();
      }

      /**
       *
       * @param start
       * @param end
       * @param multiple
       * @param unit
       *
       * @return
       */
      @Override
      public Time[] enu ( Time start , Time end , Double multiple , Unit unit ) {
            Long b = start.getTime ();
            Long e = end.getTime ();
            Double intrval = unit.convert ( multiple );
            List<Time> tmp = new ArrayList<> ( 300 );
            Long now = b;
            tmp.add ( Time.born ( now ) );
            while ( ( now + intrval.intValue () ) < e ) {
                  now += intrval.longValue ();
                  tmp.add ( Time.born ( now ) );
            }
            return To.list2Array ( tmp );
      }

      @Override
      public Time[] enu ( Integer offset , Double multiple , Unit unit ) {
            return enu ( Time.born () , offset , multiple , unit );
      }

      @Override
      public Time[] enu ( Time start , Integer offset , Double multiple , Unit unit ) {
            Integer xxx = Math.abs ( offset );
            Time[] array = new Time[ xxx ];
            Integer len = xxx;
            for ( Integer x = 0 ; x < len ; x ++ ) {
                  array[x] = start.offset ( x.doubleValue () * multiple , unit );
            }
            return array;
      }

      @Override
      public Time[] enu ( Time start , Integer offset , Unit unit ) {
            Integer xxx = Math.abs ( offset );
            Time[] array = new Time[ xxx ];
            Integer len = xxx;
            for ( Integer x = 0 ; x < len ; x ++ ) {
                  array[x] = start.offset ( x.doubleValue () , unit );
            }
            return array;
      }

      @Override
      public Time[] enu ( Integer offset , Unit unit ) {
            return enu ( Time.born () , offset , unit );
      }

      /**
       *
       * @param time
       *
       * @return
       */
      @Override
      public String format ( Time time ) {
            return null;
      }

}
